package parser;

import antlr.RecognitionException;
import java.util.*;

class StmtList extends Stmt {

    List<Stmt> statements = new ArrayList<Stmt>();

    StmtList() {
    }

    void add(Stmt s) {
        statements.add(s);
        yields |= s.yields;
        deletes |= s.deletes;
    }

    void write(ByteStream out) throws RecognitionException {
        for (Stmt s : statements)
            s.write(out);
    }

    Stmt returns() {
        int index = statements.size()-1;
        if (index < 0)
            return new ReturnStmt(Expr.NONE, 0);
        Stmt last = statements.get(index);
        if (last instanceof ReturnStmt)
            return this;
        else
            return new StmtPair(this, new ReturnStmt(Expr.NONE, 0));
    }

    String docString() {
        return statements.get(0).docString();
    }
}


